package com.hopu.v1.controller.admin.question;

import com.hopu.v1.pojo.common.PageData;
import com.hopu.v1.pojo.common.R;
import com.hopu.v1.pojo.question.Questions;
import com.hopu.v1.service.admin.question.QuestionsService;
import com.hopu.v1.vo.QuestionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author: YwaiX
 * @Version: 1.0
 * @Date: Created in 2024-09-26 14:33:03
 * @Description: 题目
 */

@RestController
@RequestMapping("/api/v1/admin/questions")
public class QuestionsController {
	
	@Autowired
	private QuestionsService questionsService;
	
	/**
	 * 分页获取题目列表
	 *
	 * @param page
	 * @param size
	 * @param questionBanksId
	 * @param questionTitle
	 * @param questionType
	 * @param status
	 * @return
	 */
	@GetMapping
	public R getQuestion(Integer page, Integer size, Integer questionBanksId, String questionTitle, String questionType, Integer status) {
		PageData<Questions> questionsList = questionsService.getQuestionsList(page, size, questionBanksId, questionTitle, questionType, status);
		return R.ok("获取成功", questionsList);
	}
	
	/**
	 * 添加题目
	 *
	 * @param questionVo
	 * @return
	 */
	@PostMapping
	public R insertQuestion(@RequestBody QuestionVo questionVo) {
		questionsService.insert(questionVo);
		return R.ok("添加成功");
	}
	
	/**
	 * 获取单个题目
	 *
	 * @param id
	 * @return
	 */
	@GetMapping("/id/{id}")
	public R getQuestionById(@PathVariable Integer id) {
		QuestionVo questionVo = questionsService.getQuestionById(id);
		return R.ok("获取成功", questionVo);
	}
	
	/**
	 * 修改题目
	 *
	 * @param questionVo
	 * @return
	 */
	@PutMapping
	public R updateQuestionById(@RequestBody QuestionVo questionVo) {
		questionsService.updateQuestionById(questionVo);
		return R.ok("修改成功");
	}
	
	/**
	 * 批量删除题目
	 *
	 * @param questionIds
	 * @return
	 */
	@DeleteMapping
	public R deleteQuestionByIds(@RequestParam List<Integer> questionIds) {
		questionsService.deleteQuestionByIds(questionIds);
		return R.ok("删除成功");
	}
}
